<%@page import="model.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	User u = new User();
	if (!u.isAdmin((String) session.getAttribute("lv"))) {
		response.sendRedirect("../index.jsp");
	}
	Categories categories = new Categories();
	National national = new National();
	String orby = (String) request.getParameter("sort");
	if (orby != null) {
		if (orby.equals("c"))
			orby = "cat_name";
		if (orby.equals("n"))
			orby = "uid";
		if (orby.equals("p"))
			orby = "position";
		if (orby.equals("by"))
			orby = "uid";
	}
	int[] cid = categories.getCID(orby);
%>
<title>MYFILM - Cat Manage</title>
<div>
	<h2>Manage Categories</h2>
</div>
<table>
	<thead>
		<tr>
			<th><a href="categories.jsp?sort=c">Category</a></th>
			<th><a href="categories.jsp?sort=p">Position</a></th>
			<th><a href="categories.jsp?sort=by">Posted by</a></th>
			<th>Edit</th>
			<th>Delete</th>
		</tr>
	</thead>
	<tbody>
	<tr><td><a href="categories.jsp?site=a">Add</a></td><td></td><td></td><td></td><td></td></tr>
		<%
			for (int i:cid) {
				categories = categories.getCatByID(i);
		%>
		<tr>
			<td><%=categories.getCat_name()%></td>
			<td><%=categories.getPosition()%></td>
			<td><%=u.getFullName(u.getUserByID(categories.getUid())
						.getUserName(), 1)%></td>
			<td><a class='edit' href='categories.jsp?site=e&cid=<%=i%>'>Edit</a></td>
			<td><a class='delete' href='delete.jsp?cid=<%=i%>'>Delete</a></td>
		</tr>
		<%
			}
		%>
		
	</tbody>
</table>